package so.ifl.commons.tools;

import javax.servlet.http.HttpServletRequest;

import so.ifl.vo.AccountVo;

/**
 *create by aaron.lu
 *create at 2012-1-10 下午1:51:56
 *<mailto: atyuan.lu@gmail.com>
 **/
public class DoradoSystemUtils {
	
	
	/**
	 * 设置当前用户
	 * create by aaron.lu
	 * create at 2012-1-10 下午2:01:52
	 * <mailto: atyuan.lu@gmail.com>
	 * @param request
	 * @param accountVo
	 *
	 */
	static public void putCurrentUser(HttpServletRequest request, AccountVo accountVo){
		if (null != accountVo && null != accountVo.getAccoutId()) {
			request.getSession().setAttribute(Constant.SESSION_USER_KEY, accountVo);
		}
		
	}
	
	/**
	 * 设置当前用户为空
	 * create by aaron.lu
	 * create at 2012-1-10 下午2:03:11
	 * <mailto: atyuan.lu@gmail.com>
	 * @param request
	 *
	 */
	static public void  setNullCurrentUser(HttpServletRequest request){
		request.setAttribute(Constant.SESSION_USER_KEY, null);
	}
	
	/**
	 * 获取当前用户
	 * create by aaron.lu
	 * create at 2012-1-10 下午2:37:08
	 * <mailto: atyuan.lu@gmail.com>
	 * @param request
	 * @return
	 *
	 */
	static public AccountVo getCurrentUser(HttpServletRequest request){
		AccountVo accountVo = null;
		Object object = request.getSession().getAttribute(Constant.SESSION_USER_KEY);
		
		if (object instanceof AccountVo) {
			accountVo = (AccountVo)object;
		}
		return accountVo;
	}

}
